package com.witframework.web.tag;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.BodyContent;
import javax.servlet.jsp.tagext.BodyTagSupport;

public class InfoBoxTag extends BodyTagSupport
{
  private String id = null;
  private String size = "240";
  private String className = null;
  private String titleClass = null;
  private String bodyClass = null;
  private String title = null;
  private String background = "#FFCC00";
  private String titleBackground = "#66ff33";
  private String sBody = null;
  private static final String INFOBOXTAG = "nfbxtgcj2006";
  private static final String DEFAULT_STYLE = "margin:0 0 4px 0;padding:0;";
  private static final String DEFAULT_TITLE_STYLE = "margin:0 0 2px;padding:2px 0 0 6px;border-bottom:2px solid #fff;color:#000000;text-align:left;font-size:100%;text-transform:uppercase;font-weight:bold;";
  private static final String DEFAULT_BODY_STYLE = "margin:0;padding:0 8px 6px 8px;text-align:left;font-size:80%;line-height:1.2em;color:#000000;text-align:justify;";

  public void setId(String paramString)
  {
    this.id = paramString;
  }

  public String getId()
  {
    return this.id;
  }

  public void setSize(String paramString)
  {
    this.size = paramString;
  }

  public String getSize()
  {
    return this.size;
  }

  public void setClassName(String paramString)
  {
    this.className = paramString;
  }

  public String getClassName()
  {
    return this.className;
  }

  public void setTitle(String paramString)
  {
    this.title = paramString;
  }

  public String getTitle()
  {
    return this.title;
  }

  public void setTitleClass(String paramString)
  {
    this.titleClass = paramString;
  }

  public String getTitleClass()
  {
    return this.titleClass;
  }

  public void setBodyClass(String paramString)
  {
    this.bodyClass = paramString;
  }

  public String getBodyClass()
  {
    return this.bodyClass;
  }

  public void setBackground(String paramString)
  {
    this.background = paramString;
  }

  public String getBackground()
  {
    return this.background;
  }

  public void setTitleBackground(String paramString)
  {
    this.titleBackground = paramString;
  }

  public String getTitleBackground()
  {
    return this.titleBackground;
  }

  public int doAfterBody()
    throws JspException
  {
    BodyContent localBodyContent = getBodyContent();
    if (localBodyContent != null)
    {
      this.sBody = localBodyContent.getString();
      localBodyContent.clearBody();
    }
    if (this.sBody == null)
      this.sBody = "";
    else
      this.sBody = this.sBody.trim();
    return 0;
  }

  public int doEndTag()
    throws JspException
  {
    StringBuffer localStringBuffer = new StringBuffer("");
    if ((!(this.size.equals("240"))) && (!(this.size.equals("120"))))
      throw new JspException("This version of InfoBox supports size 120 or 240");
    if (this.id == null)
    {
      Integer localInteger = (Integer)this.pageContext.getAttribute("nfbxtgcj2006", 1);
      if (localInteger == null)
        localInteger = new Integer(1);
      this.pageContext.setAttribute("nfbxtgcj2006", new Integer(localInteger.intValue() + 1), 1);
      this.id = "nfbxtgcj2006" + localInteger.intValue();
    }
    localStringBuffer.append("<dl id=\"");
    localStringBuffer.append(this.id);
    localStringBuffer.append("\"");
    if (this.className != null)
    {
      localStringBuffer.append(" class=\"" + this.className + "\"");
    }
    else
    {
      localStringBuffer.append(" style=\"");
      localStringBuffer.append("margin:0 0 4px 0;padding:0;");
      localStringBuffer.append("width:");
      localStringBuffer.append(this.size);
      localStringBuffer.append("px;");
      if (this.background != null)
        localStringBuffer.append("background:" + this.background);
      else
        localStringBuffer.append("background:");
      localStringBuffer.append(" url(infobox_b");
      localStringBuffer.append(this.size);
      localStringBuffer.append(".gif) no-repeat bottom left;");
      localStringBuffer.append("\"");
    }
    localStringBuffer.append(">");
    localStringBuffer.append("<dt id=\"");
    localStringBuffer.append(this.id + "_title");
    localStringBuffer.append("\"");
    if (this.titleClass != null)
    {
      localStringBuffer.append(" class=\"" + this.titleClass + "\"");
    }
    else
    {
      localStringBuffer.append(" style=\"");
      localStringBuffer.append("margin:0 0 2px;padding:2px 0 0 6px;border-bottom:2px solid #fff;color:#000000;text-align:left;font-size:100%;text-transform:uppercase;font-weight:bold;");
      if (this.titleBackground != null)
        localStringBuffer.append("background:" + this.titleBackground);
      else
        localStringBuffer.append("background:");
      localStringBuffer.append(" url(infobox_t");
      localStringBuffer.append(this.size);
      localStringBuffer.append(".gif) no-repeat top left;");
      localStringBuffer.append("\"");
    }
    localStringBuffer.append(">");
    if (this.title != null)
      localStringBuffer.append(this.title);
    localStringBuffer.append("</dt>");
    localStringBuffer.append("<dd id=\"");
    localStringBuffer.append(this.id + "_body");
    localStringBuffer.append("\"");
    if (this.bodyClass != null)
    {
      localStringBuffer.append(" class=\"" + this.bodyClass + "\"");
    }
    else
    {
      localStringBuffer.append(" style=\"");
      localStringBuffer.append("margin:0;padding:0 8px 6px 8px;text-align:left;font-size:80%;line-height:1.2em;color:#000000;text-align:justify;");
      localStringBuffer.append("\"");
    }
    localStringBuffer.append(">");
    localStringBuffer.append(this.sBody);
    localStringBuffer.append("</dd>");
    localStringBuffer.append("</dl>");
    try
    {
      this.pageContext.getOut().write(localStringBuffer.toString());
    }
    catch (Exception localException)
    {
      throw new JspException("Could not write data " + localException.toString());
    }
    dropData();
    return 6;
  }

  public void release()
  {
    super.release();
    dropData();
  }

  private void dropData()
  {
    this.id = null;
    this.size = "240";
    this.className = null;
    this.titleClass = null;
    this.bodyClass = null;
    this.title = null;
    this.background = "#FFCC00";
    this.titleBackground = "#66ff33";
    this.sBody = null;
  }
}